//
//  getData.m
//  BaiKT
//
//  Created by HOCVIEN on 4/21/15.
//  Copyright (c) 2015 HuynhTridung. All rights reserved.
//

#import "GetData.h"

@implementation GetData

+ (NSDictionary *)loadData {
    NSURL *url = [NSURL URLWithString:@"http://food2fork.com/api/search?key=2d64c4bc219c56f7509860a5afa36fe1"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    NSURLResponse *response;
    NSError *error;
    //send it synchronous
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    //    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
    // check for an error. If there is a network error, you should handle it here.
    if(!error)
    {
        //log response
        NSLog(@"Response from server = %@", dict);
        
        NSLog(@"count %d",[dict[@"count"] intValue]);
    }
    return  dict;
}

@end
